﻿using System;

namespace Demo0604
{
    class Program
    {
        static void Main(string[] args)
        {
            //变量&引用
            Gameplayer g = new Gameplayer();//玩家
            ManMachine man = new ManMachine();//人机
            Judgment jud = new Judgment();//裁判
            int time = 0;//总次数
            int r=0;//人机
            int w = 0;//玩家
            string flag = null;
        logio:
                Front();//开头
            
            Console.WriteLine("出拳规则：{0}",ListFist());
            Console.WriteLine("请选择对方角色<{0}>",Machinename());
            int key = int.Parse(Console.ReadLine());
            man.Name = ((Man)key).ToString();//人机姓名
            Console.WriteLine("请输入您的姓名：");
            g.Name= Console.ReadLine();//玩家姓名
            //循环1
            while (true)
            {
            Console.WriteLine("{0}vs{1}\t对战",g.Name,man.Name);
            Console.WriteLine("开始游戏吗？（y/n）");
            flag = Console.ReadLine();
                 if (flag.Equals("y"))
                 {
                    break;
                 }
            }
            while (true)
            {
                Console.WriteLine("\n\r请出拳：{0}(输入相应数字：)",ListFist());
                int gnum = g.ShowFist();//玩家出拳
                int mannum = man.ShowFist();//人机出拳
                Console.WriteLine("{0}：出拳：{1}",g.Name,(Fist)gnum);
                Console.WriteLine("{0}：出拳：{1}",man.Name,(Fist)mannum);//随机数
                int a = jud.Port(gnum,mannum);
                User(a,g.Name);
                if (a==1)
                {
                    w++;
                }
                if (a==-1)
                {
                    r++;
                }
                time++;
                Console.WriteLine("是否开始进行下一轮？（y/n）");
                flag = Console.ReadLine();
                if (flag.Equals("n"))
                {
                    break;
                }
            }
            Console.WriteLine("===========================");
            Console.WriteLine("{0}\tvs\t{1}",man.Name,g.Name);
            Console.WriteLine("对战次数：{0}",time);
            Console.WriteLine("姓名\t得分");
            Console.WriteLine("{0}\t{1}",g.Name,w);
            Console.WriteLine("{0}\t{1}",man.Name,r);
            if (w>r)
            {
                Console.WriteLine("你赢了。");
            }
            else
            {
                Console.WriteLine("你输了");
            }
            Console.WriteLine("要开始进行下一轮？（y/n）");
            flag = Console.ReadLine();
            if (flag.Equals("y"))
            {
                time = 0;
                r = 0;
                w = 0;
                goto logio;
            }
            else
            {
                Console.WriteLine("系统退出！");
            }
        }

        private static void Front()
        {
            //开头
            Console.WriteLine("-------------欢迎进入游戏世界---------------");
            Console.WriteLine("***************************");
            Console.WriteLine("*********猜拳，开始********");
            Console.WriteLine("***************************");
        }

        private static void User(int a,string name)
        {
            if (a == 0)
            {
                Console.WriteLine("和局，真衰！呵呵，等着瞧吧！");
            }
            else if (a == 1)
            {
                Console.WriteLine("恭喜，{0}赢了",name);
            }
            else
            {
                Console.WriteLine("嘿，笨蛋，你输了！");
            }
        }
        //剪刀石头布
        static string ListFist() 
        {
            string fistString = "";
            int i = 1;
            foreach (Fist f in Enum.GetValues(typeof(Fist)) )
            {
                fistString += i + "、" + f + "；";
                i++;
            }
            return fistString;
        }
        //人机名字
        static string Machinename() 
        {
            string fistString = "";
            int i = 1;
            foreach (Man m in Enum.GetValues(typeof(Man)))
            {
                fistString += i + "：" + m + "；";
                i++;
            }
            return fistString;
        }
    }
}
